/*   
   	 ************************************************************************
	 AUTHOR     : KEITH WESTPHAL
     METHOD     : SEARCH VIEW
     PROCESS    : FORMATS THE DATA COMMING FROM THE SEARCHUSER DB CLASS
     CONNECTIONS: SEARCHRESULTS.JSP, SEARCH.JAVA, USERDB.GETUSERSEARCH 
     ************************************************************************
*/

package actions;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.User;

import data.UserDB;

public class Search extends Action {

	@Override
	protected void setURLMapping() {
		// TODO Auto-generated method stub
		urlMapping = "/Search";
	}

	@Override
	protected String doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String searchIn = request.getParameter("searchIn");
		ArrayList<User> users = new ArrayList<User>();
		String url = "WEB-INF/views/content/Home.jsp";
		
		if (searchIn == null)
		{
			
		}
		else
		{
			users = UserDB.getUserSearch(searchIn);
			request.setAttribute("users", users);
			
			url = "/WEB-INF/views/content/SearchResults.jsp";
		}
		return url;
	}

	@Override
	protected String doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String searchIn = request.getParameter("searchIn");
		
		return "Search?searchIn=" + searchIn;
	}

	@Override
	protected void setupPage(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

}
